import { createApp } from 'vue'
import { createPinia } from 'pinia'
import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/reset.css'
import App from './App.vue'
import router from './router'
import i18n from './locales'
import { useAuthStore } from './stores/auth'
import { setupErrorHandler } from './utils/errorHandler'
import { wsService } from './services/websocket'

// 创建Vue应用实例
const app = createApp(App)
const pinia = createPinia()

app.use(pinia)
app.use(router)
app.use(Antd)
app.use(i18n)

// 初始化认证状态
const authStore = useAuthStore()

// 如果有 token，自动恢复登录状态
if (authStore.token) {
  // 可以在这里添加 token 验证逻辑
}

// 初始化WebSocket服务
console.log('[Main] 初始化WebSocket服务...')
wsService.ensureInitialized()

// 注册错误处理器
setupErrorHandler()

// 挂载应用
app.mount('#app') 